const mongoose = require("mongoose");
const ordersModel = mongoose.model("orders");

module.exports = {
        get: async ({ page, limit }) => {
                limit = ~~limit;
                const result = {};
                result.total = await ordersModel.countDocuments();
                result.rows = await ordersModel.find().populate([
                        {
                                path: 'schedulesId',//设置字段
                                populate: {
                                        path: 'movieId'
                                }
                        },
                        {
                                path: 'schedulesId',//设置order字段
                                populate: {
                                        path: 'cinemasId'
                                }
                        },
                        {
                                path: 'schedulesId',//设置order字段
                                populate: {
                                        path: 'theaterId'
                                }
                        },
                        // 'schedulesId',
                        "usersId",
                ]

                ).skip((page - 1) * limit).limit(limit).exec();
                console.log(result.rows);
                return result;
        },
        add: async (order) => await ordersModel.create(order),
}

// ["schedulesId", "usersId"]